<%@ Page Language="C#" MasterPageFile="app-frame.master" AutoEventWireup="true" CodeFile="QueryBuilder.aspx.cs" Inherits="QueryBuilder" Title="MaxBlox" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder3" Runat="Server">
<script type="text/javascript" src="scripts/QueryDesigner.js" language="javascript"></script>
    <table style="width: 100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
            <td>
                <asp:Label ID="lblMessage" runat="server" CssClass="defaultFont" Font-Size="X-Small" ForeColor="Black"></asp:Label></td>
        </tr>
        <tr>
        <td class="Dynamic_PageHeaderRow">
            <asp:Label ID="lblHeader" runat="server" Text="Query Designer - Add" Width="207px"></asp:Label></td>
        </tr>
        <tr>
            <td id="td_Page_ToopTip" runat="server">
            </td>
        </tr>
    </table>

    <table id="TABLE1" style="width: 100%; table-layout:fixed; margin-left:2px;" cellpadding="2" cellspacing="0" border="0" runat="server">
        <tr>
            <td style="width: 20%;">
                <asp:Label ID="lbl_id" runat="server" Text="Query Id" Visible="False" CssClass="controlLabelFont"></asp:Label></td>
            <td style="width: 75%;">
                <asp:TextBox ID="p_sy_report_sql_report_base_id" runat="server" Enabled="False"
                    Width="238px" Visible="False" CssClass="controlFont"></asp:TextBox></td>
        </tr>
        <tr>
            <td style="width: 20%;">
                <asp:Label ID="lblQName" runat="server" Text="Query Name" CssClass="controlLabelFont"></asp:Label></td>
            <td style="width: 75%;">
                <asp:TextBox ID="p_sy_report_sql_report_base_name" runat="server" Width="238px" CssClass="controlFont"></asp:TextBox>
                <img alt="Required Field" src="Images/star.gif"/>
                <asp:RequiredFieldValidator ID="rfv_p_sy_report_sql_report_base_name" runat="server" ErrorMessage="This is a requied field." Display="None" ControlToValidate="p_sy_report_sql_report_base_name" />
                <cc1:ValidatorCalloutExtender ID="vce_p_sy_report_sql_report_base_name" runat="server" TargetControlID="rfv_p_sy_report_sql_report_base_name" WarningIconImageUrl="Images/warning_small.gif" HighlightCssClass="maskInvalid" />
            </td>
        </tr>
        <tr>
            <td style="width: 20%;">
                <asp:Label ID="lblQDesc" runat="server" Text="Query Description" CssClass="controlLabelFont"></asp:Label></td>
            <td style="width: 75%;">
                <asp:TextBox ID="p_sy_report_sql_report_base_desc" runat="server"
                    Rows="3" TextMode="MultiLine" Width="238px" CssClass="controlFont"></asp:TextBox></td>
        </tr>
        <tr>
            <td style="width: 20%;">
                <asp:Label ID="lbl_Primary_object_id" runat="server" Text="Primary Object" CssClass="controlLabelFont" Visible="false"></asp:Label></td>
            <td style="width: 75%;">
                <asp:DropDownList ID="p_sy_report_sql_primary_object_id" runat="server" Width="238px" CssClass="controlFont" Visible="false">
                </asp:DropDownList></td>
        </tr>
        <tr>
            <td colspan="2" style="width: 100%; padding-left:0;">

            <asp:UpdatePanel ID="up_querybuilder" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
            <table width="100%">
                <tr style="height:28px;">
                    <td style="width:20%;">
                        <asp:Label ID="lblQBuild" runat="server" Text="Select an object:" CssClass="controlLabelFont"></asp:Label>
                    </td>
                    <td style="width:75%;">
                        <table>
                        <tr>
                            <td>
                                <asp:Label ID="lblColNames" CssClass="controlLabelFont" Text="Select the fields:" runat="server" Visible="false"></asp:Label>
                            </td>
                            <td>
                                <div>
                                    <asp:UpdateProgress id="UpProg_Query_builder" runat="server" AssociatedUpdatePanelID="up_querybuilder">
                                    <ProgressTemplate>
                                        <asp:Image ID="Image1New" runat="server" ImageUrl="Images/load.gif" />
                                        <asp:Label ID="lbl_working_6" runat="server" CssClass="controlFont" Text=" Loading..."></asp:Label>
                                    </ProgressTemplate>
                                    </asp:UpdateProgress>
                                </div>
                            </td>
                        </tr>
                        </table>
                    </td>
                </tr>
                <tr>
                    <td rowspan="2" style="width:20%;">
                        <asp:ListBox ID="p_sy_report_sql_list_object" runat="server" AutoPostBack="true" onchange="javascript:uncheckUserQuery();" Height="300px" Width="100%" CssClass="controlFont"></asp:ListBox>
                    </td>
                    <td style="height:150px;">
                        <asp:Panel ID="pnlChbxColumn" runat="server" Height="150px" ScrollBars="Auto" Width="200px">
                            <asp:CheckBoxList ID="cblColumns" CssClass="controlFont" runat="server" AutoPostBack="true" Height="150px" CellPadding="0" CellSpacing="0"></asp:CheckBoxList>
                        </asp:Panel>
                    </td>
                </tr>
                <tr>
                    <td style="width:75%;">
                        <div style="height:20px;">
                        <asp:Label ID="lblQExpr" CssClass="controlLabelFont" Text="Query Expression:" runat="server" Visible="false"></asp:Label>
                        </div>
                        <asp:Panel ID="pnl_Sql_Expression" runat="server" Height="122px" ScrollBars="Auto" style="white-space:nowrap;" Width="500px" Visible="false">
                        </asp:Panel>
                    </td>
                </tr>
                
            </table>
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="p_sy_report_sql_list_object" EventName="SelectedIndexChanged" />
                <asp:AsyncPostBackTrigger ControlID="cblColumns" EventName="SelectedIndexChanged" />
            </Triggers>
            </asp:UpdatePanel>
            </td>
        </tr>
        <tr>
                    <td style="width: 20%;">
                        <asp:Label ID="Label3" runat="server" Text="Query" CssClass="controlLabelFont"></asp:Label>
                        <div>
                            <asp:UpdateProgress id="up_Prog_QueryText" runat="server" AssociatedUpdatePanelID="up_QueryText">
                            <ProgressTemplate>
                                <asp:Image ID="Image1" runat="server" ImageUrl="Images/load.gif" />
                                <asp:Label ID="lbl_working" runat="server" CssClass="controlFont" Text=" Loading..."></asp:Label>
                            </ProgressTemplate>
                            </asp:UpdateProgress>
                        </div>
                    </td>
                    
                    <td> 
                    <asp:UpdatePanel ID="up_QueryText" runat="server" UpdateMode="Always">
                    <ContentTemplate>
                        <asp:TextBox ID="txt_sql_builder" runat="server" Rows="5" TextMode="MultiLine" Width="500px" CssClass="controlFont" Visible="false"></asp:TextBox>
                        <asp:TextBox ID="p_sy_report_sql_report_base_sql" runat="server" Rows="5" onchange="javascript:checkUserQuery();" TextMode="MultiLine" Width="500px" CssClass="controlFont"></asp:TextBox>
                        <img alt="Required Field" src="Images/star.gif"/>
                        <asp:RequiredFieldValidator ID="rfv_p_sy_report_sql_report_base_sql" runat="server" ErrorMessage="This is a requied field." Display="None" ControlToValidate="p_sy_report_sql_report_base_sql" />
                        <cc1:ValidatorCalloutExtender ID="vce_p_sy_report_sql_report_base_sql" runat="server" TargetControlID="rfv_p_sy_report_sql_report_base_sql" WarningIconImageUrl="Images/warning_small.gif" HighlightCssClass="maskInvalid" /><br />
                        <asp:Label runat="server" ID="lblQ" CssClass="controlLabelFont" Text="Use the parameter name enclosed with $ symbol in the Query. For example, select * from table_name where field_id='$parameter_name$'."></asp:Label>
                    </ContentTemplate>
                    </asp:UpdatePanel>
                    </td>
                    
        </tr>
        <tr>
            <td style="width: 20%;">
                <asp:Label ID="lbl_Parameter" runat="server" Text="Parameters" CssClass="controlLabelFont"></asp:Label></td>
            <td style="width: 75%;">
                <asp:TextBox ID="p_sy_report_sql_report_base_param" runat="server" Rows="3" onchange="javascript:checkUserQuery();" TextMode="MultiLine" Width="500px" CssClass="controlFont"></asp:TextBox><br />
                <asp:Label ID="lblP" runat="server" Text="Parameters Syntax: [sequence_number][parameter_name][table_name.field_name]=default value. Parameters are separated by comma(,) and enclosed with square brackets[]." CssClass="controlLabelFont"></asp:Label></td>
        </tr>
        <tr>
            <td style="width: 20%;">
                <asp:Label ID="lbl_sysquery" runat="server" Text="Is System Query" Visible="False" CssClass="controlLabelFont"></asp:Label></td>
            <td style="width: 75%;">
                <asp:CheckBox ID="p_sy_report_sql_is_system_query" runat="server" Width="238px" Visible="False" CssClass="controlFont" />
            </td>
        </tr>
        <tr>
            <td style="width: 20%;">
                <asp:Label ID="lbl_Owner" runat="server" Text="Owner" CssClass ="Controllabelfont"></asp:Label>
            </td>
            <td id="tdownerid" runat="server" style="width: 75%;">
                <asp:DropDownList ID="p_sy_report_sql_owner_id_dd" runat="server" CssClass="controlFont" Visible="False"></asp:DropDownList>
                <asp:TextBox ID="txt_p_sy_report_sql_owner_id" runat="server" CssClass="controlFont"></asp:TextBox>
                <asp:HiddenField ID="p_sy_report_sql_owner_id" runat="server" />
                <img id="imgOwnerSearch" runat="server" alt="Click here for Lookup Window" src="Images/search.gif" class="SearchPopup" onclick="javascript:openlookupwindow('p_sy_report_sql_owner_id','txt_p_sy_report_sql_owner_id','f496930dfe0b690f','','');" />
            </td>
        </tr>
        <tr class="Dynamic_HtmlTableBottom">
            <td colspan="2" style="width:100%">
                <asp:Button ID="btnCheck" runat="server" UseSubmitBehavior="false" OnClick="btnCheck_Click" Text="Check" OnClientClick="javascript:disableThis('ctl00_ContentPlaceHolder3_btnCheck','Parsing....'); disableThisNoValidation('ctl00_ContentPlaceHolder3_btnSave','Save'); disableThisNoValidation('ctl00_ContentPlaceHolder3_btnUpdate','Save')"/>
                <asp:Button ID="btnSave" runat="server" UseSubmitBehavior="true" OnClick="btnSave_Click"  Text="Save" OnClientClick="javascript:disableThis('ctl00_ContentPlaceHolder3_btnSave','Saving....'); disableThis('ctl00_ContentPlaceHolder3_btnCheck','Parse');" />
                <asp:Button ID="btnUpdate" runat="server" UseSubmitBehavior="true" OnClick="btnUpdate_Click" Text="Save" OnClientClick="javascript:disableThis('ctl00_ContentPlaceHolder3_btnUpdate','Saving....'); disableThis('ctl00_ContentPlaceHolder3_btnCheck','Parse');" />
                <asp:Button ID="btnReset" runat="server" Text="Reset" UseSubmitBehavior="false" OnClick="btnReset_Click"  />
            </td>
        </tr>
    </table>
   
                <asp:HiddenField ID="p_sy_report_sql_af_row_id" runat="server" />
                <asp:HiddenField ID="p_sy_report_sql_created_at" runat="server" />
                <asp:HiddenField ID="p_sy_report_sql_created_by" runat="server" />
            <asp:HiddenField ID="p_sy_report_sql_is_user_query" runat="server" />
</asp:Content>